package com.songlanyun.modules.protocol.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.validator.ValidatorUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.protocol.dao.SysProtocolDao;
import com.songlanyun.modules.protocol.entity.SysProtocolEntity;
import com.songlanyun.modules.protocol.service.SysProtocolService;


@Service("sysProtocolService")
public class SysProtocolServiceImpl extends ServiceImpl<SysProtocolDao, SysProtocolEntity> implements SysProtocolService {


    /**
     * 内部调用
     * @param entity
     * @return
     */
    @Override
    public SysProtocolEntity create(SysProtocolEntity entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.insert(entity);
        return entity;
    }

    /**
     * 内部调用
     * @param entity
     * @return
     */
    @Override
    public SysProtocolEntity modify(SysProtocolEntity entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.updateById(entity);
        return entity;
    }


    /**
     * 获取协议
     * @return
     */
    @Override
    public SysProtocolEntity get() {
        return this.getOne(new LambdaQueryWrapper<SysProtocolEntity>().last("limit 1"));
    }

    /**
     * 设置会员注册协议
     * @param entity
     * @return
     */
    @Override
    public SysProtocolEntity setUserProtocol(SysProtocolEntity entity) {
        SysProtocolEntity sysProtocolEntity = this.get();
        if(sysProtocolEntity==null)
        {
            return this.create(entity);
        }
        else
        {
            sysProtocolEntity.setUserProtocol(entity.getUserProtocol());
            return this.modify(sysProtocolEntity);
        }

    }

    /**
     * 设置商家注册协议
     * @param entity
     * @return
     */
    @Override
    public SysProtocolEntity setShopProtocol(SysProtocolEntity entity) {
        SysProtocolEntity sysProtocolEntity = this.get();
        if(sysProtocolEntity==null)
        {
            return this.create(entity);
        }
        else
        {
            sysProtocolEntity.setShopProtocol(entity.getShopProtocol());
            return this.modify(sysProtocolEntity);
        }
    }

    @Override
    public void remove(Integer id) {

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        return null;
    }
}